﻿using System;
using System.Data;
using System.Web.UI;

using BLL;
using Model;
using Utility;

namespace EvaluationSystem.Answer
{
    public partial class Notice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["isTesting"] == null)//如果没有输入序列号，则禁止访问此页面
            {
                Response.Redirect("Tlogin.aspx");
            }

            btnNext.Enabled = false;
            if (!IsPostBack)
            {
                if (Request.QueryString["logopath"] != null)
                {
                    if (string.IsNullOrEmpty(Request.QueryString["logopath"]))
                    {
                        usrLogo.ImageUrl = "~/images/5050.jpg";
                        usrLogo.Visible = false;
                    }
                    else
                    {
                        usrLogo.ImageUrl = Request.QueryString["logopath"].ToString().Replace("\\", "/");
                    }
                }
                string companyName = string.Empty;
                int totalMinutes = 50;
                
                int xiaxian = 0;
                int shangxian = 0;
                
                if (!string.IsNullOrEmpty(Request.QueryString["guid"]))
                {
                    GuidBLL gbll = new GuidBLL();
                    QuestionBLL qbll = new QuestionBLL();
                    ActivityBLL abll = new ActivityBLL();

                    int aID = gbll.GetActivityId(Request.QueryString["guid"]);
                    totalMinutes = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"],1) / 60;

                    xiaxian = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"], 2) / 60;
                    shangxian = qbll.GetQuestionTimeByGUID(Request.QueryString["guid"], 3) / 60;
                    
                    DataSet ds = abll.GetEUsrInfoByActivityId(aID);

                    if (ds != null)
                    {
                        companyName = ds.Tables[0].Rows[0]["users_incname"].ToString();
                    }
                }
                txtWelcome.Text = @"  欢迎您参加" + companyName + "组织的题目测试，本次测试需要"

                + xiaxian.ToString() + "-" + shangxian.ToString() + "分钟左右的时间。";
            }
        }

        protected void btnCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Write("<script>");
            Response.Write("{top.opener =null;top.close();}");
            Response.Write("</script>");
        }

        protected void btnNext_Click(object sender, ImageClickEventArgs e)
        {
            if (chkRules.Checked == true)
            {
                Response.Redirect("TesterInfoInput.aspx?guid=" + Request.QueryString["guid"]
                        + "&logopath=" + Request.QueryString["logopath"].Replace("\\", "/"));
            }
        }

        protected void chkRules_CheckedChanged(object sender, EventArgs e)
        {
            if (chkRules.Checked == true)
            {
                btnNext.Enabled = true;
            }
            else
            {
                btnNext.Enabled = false;
            }
        }
    }
}